package org.karelun.whiteboard.edit.properties;

import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.karelun.whiteboard.Named;
import org.karelun.whiteboard.WhiteboardPackage;

/**
 * @Author: KarelunHuang
 * @Date: Jan 30, 2013
 **/
public class NamePropertySection extends BasePropertySection<Named> {
	
	private Text text;
	
	private ISWTObservableValue textObserver;
	
	public NamePropertySection() {
	}

	@Override
	protected String getSectionTitle() {
		return "Name";
	}

	@Override
	protected void doCreateControl(Composite parent) {
		text = new Text(parent,SWT.BORDER);
		text.setLayoutData(new GridData(GridData.FILL_BOTH));
		textObserver=WidgetProperties.text(SWT.Modify).observe(text);
	}

	@Override
	protected void dataBinding() {
		Named selected = getSelectedObjectModel();
		dataBinding(textObserver, selected,WhiteboardPackage.Literals.NAMED__NAME);
	}
	
	@Override
	public void refresh() {
		if(text==null||text.isDisposed()){
			return;
		}
		text.setEnabled(isEditable());
	}
}
